package com.moon.utils;

import com.moon.entity.TProduct;
import com.moon.vo.ProductVo;

import java.util.Arrays;

//商品图片地址使用形式转换
public class ProductUtils {

    public static ProductVo getList(TProduct product) {
        ProductVo vo = new ProductVo();
        vo.setId(product.getId());
        vo.setSellerId(product.getSellerId());
        vo.setProductName(product.getProductName());
        vo.setProductImgList(Arrays.asList(product.getProductImg().split(";")));
        vo.setProductDetail(product.getProductDetail());
        vo.setStatus(product.getStatus());
        return vo;
    }

    public static TProduct getString(ProductVo vo) {
        StringBuilder sb = new StringBuilder();
        for (String str : vo.getProductImgList()) {
            sb.append(str + ";");
        }
        sb.setLength(sb.length() - 1);
        TProduct product = new TProduct();
        product.setId(vo.getId());
        product.setSellerId(vo.getSellerId());
        product.setProductName(vo.getProductName());
        product.setProductImg(sb.toString());
        product.setProductDetail(vo.getProductDetail());
        product.setStatus(vo.getStatus());
        return product;
    }
}
